package com.tgy.twoDatabase.service.impl;

import com.tgy.twoDatabase.entity.Sendmessagelog;
import com.tgy.twoDatabase.dao.logDB.SendmessagelogDao;
import com.tgy.twoDatabase.service.SendmessagelogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Future;

/**
 * (Sendmessagelog)表服务实现类
 *
 * @author makejava
 * @since 2021-10-02 10:25:36
 */
@Service("sendmessagelogService")
public class SendmessagelogServiceImpl implements SendmessagelogService {
    Logger log = LoggerFactory.getLogger(SendmessagelogServiceImpl.class);


    @Resource
    private SendmessagelogDao sendmessagelogDao;

    //异步线程有返回值
    @Override
    @Async("taskExecutor")
    public Future<Map<String,Object>> insert(Sendmessagelog sendmessagelog) {
/*        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/
        Map<String, Object> map = new HashMap<String, Object>();
        int list = sendmessagelogDao.insert(sendmessagelog);
        map.put("code", 0);
        map.put("msg", "");
        map.put("data", list);
        log.info("发送短信日志方法----  执行开始");// 模拟耗时
        System.out.println(map);
        log.info("发送短信日志方法----  执行结束");
        return new AsyncResult<>(map);
    }

    @Override
    public Map<String, Object> queryAll(Sendmessagelog sendmessagelog) {
        Map<String, Object> map = new HashMap<String, Object>();
        List<Sendmessagelog> list = sendmessagelogDao.queryAll(sendmessagelog);
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", list.size());
        map.put("result", list);
        return map;
    }

}
